package Classes.GameUtils
{
	import Classes.GameDatas.GD_AllFriends;
	import Classes.GameDatas.GD_Item;
	import Classes.GameDatas.GD_Player;
	import Classes.GameViews.GV_Map;
	import Classes.GameViews.ViewPanels.VP_errorPanel;
	import Classes.Managers.M_Communication;
	import Classes.Managers.M_ConfigData;
	import Classes.Managers.M_Languages;
	import Classes.staticinfo.Language;
	
	import UIComponents.IHavenWall;

	public class HavenWall_deal implements IHavenWall
	{
		private static var _instance:HavenWall_deal;

		public function HavenWall_deal()
		{
		}

		public static function get instance():HavenWall_deal
		{
			if (!_instance)
				_instance=new HavenWall_deal();
			return _instance;
		}
		
		public function getLandInfoByLandId(landLv:Number):HavenWall_deal
		{
			var obj:Object=GV_Map.havenSetConfigDataAry[landLv];
			this.landId=obj.zt_land_id;
			this.landGreade=obj.zt_land_greade;
			this.houseBuildingLv=obj.zt_building_lv;
			this.landFriendNum=obj.zt_land_friends;
			this.landNeedMoney=obj.zt_land_money;
			this.landNeedOMoney=obj.zt_land_omoney;
			this.addLandNum=obj.zt_land_add;
			this.landPow=obj.zt_land_power;
			var oldObj:Object=GV_Map.getHavenObjByHavenLv(landLv);
			this.oldWallW=oldObj.width*2;
			this.oldWallH=oldObj.height*2;
			var newObj:Object=GV_Map.getHavenObjByHavenLv((landLv+1));
			this.newWallW=newObj.width*2;
			this.newWallH=newObj.height*2;
			return HavenWall_deal.instance;
		}
		
		/**
		 * 拓展土地 
		 * @param type 1:o币 || 2:朋友 ||3:金币
		 */		
		public function expendLandFun(type:Number):void
		{
			switch(type)
			{
				case 1 :
					if(this.isReachOMoney() && this.isReachUserLv() && this.isReachMainHouseLv())
					{
						M_Communication.instance.send(12306,{levelID:this.landId,typeId:1});
					}else{
						VP_errorPanel.instance.setErrorMessage(Language.notEnoughExpendLand);
						VP_errorPanel.instance.enterFrame();
						GU_Sound.instance.playCommSound("System_Prompt");
					}
					break;
				case 2:
					if(this.isReachFriendNum() && this.isReachUserLv() && this.isReachMainHouseLv())
					{
						M_Communication.instance.send(12306,{levelID:this.landId,typeId:2});
					}else{
						VP_errorPanel.instance.setErrorMessage(Language.notEnoughExpendLand);
						VP_errorPanel.instance.enterFrame();
					}
					break;
				case 3 :
					if(this.isReachMoney() && this.isReachUserLv() && this.isReachMainHouseLv())
					{
						M_Communication.instance.send(12306,{levelID:this.landId,typeId:3});
					}else{
						VP_errorPanel.instance.setErrorMessage(Language.notEnoughExpendLand);
						VP_errorPanel.instance.enterFrame();
					}
					break;
			}
		}

		/**
		 * 土地ID
		 */
		public function get landId():Number
		{
			return _landId;
		}

		/**
		 * @private
		 */
		public function set landId(value:Number):void
		{
			_landId = value;
		}

		/**
		 * 开发土地需要玩家等级
		 */
		public function get landGreade():Number
		{
			return _landGreade;
		}
		
		/**
		 * 用户等级是否达到 
		 * @return 
		 */		
		public function isReachUserLv():Boolean
		{
			return GD_Player.instance.playerLv>=landGreade;
		}

		/**
		 * @private
		 */
		public function set landGreade(value:Number):void
		{
			_landGreade = value;
		}

		/**
		 * 需要友人的个数
		 */
		public function get landFriendNum():Number
		{
			return _landFriendNum;
		}
		
		/**
		 * 朋友个数是否达到 
		 * @return 
		 */		
		public function isReachFriendNum():Boolean
		{
			return GD_AllFriends.instance.getFriendNumByLv()>=landFriendNum;
		}

		/**
		 * @private
		 */
		public function set landFriendNum(value:Number):void
		{
			_landFriendNum = value;
		}

		/**
		 * 开发土地需要的欧币
		 */
		public function get landNeedOMoney():Number
		{
			return _landNeedOMoney;
		}
		

		/**
		 * @private
		 */
		public function set landNeedOMoney(value:Number):void
		{
			_landNeedOMoney = value;
		}
		
		/**
		 * O币是否达到 
		 * 
		 */		
		public function isReachOMoney():Boolean
		{
			var flag:Boolean=GD_Player.instance.gold>=landNeedOMoney;
			if(M_ConfigData.instance.isOpenQQVip)
			{
				
				var item:GD_Item=GD_Player.instance.getItemByType(10100049);
				if(null==item || item.itemNumber<landNeedOMoney)
				{
					flag=false;
				}else{
					flag=true;
				}
			}
			return flag;
		}
		
		/**
		 * 金币是否达到 
		 * 
		 */		
		public function isReachMoney():Boolean
		{
			return GD_Player.instance.money>=landNeedMoney;
		}

		/**
		 * 开发土地需要的金币 
		 */
		public function get landNeedMoney():Number
		{
			return _landNeedMoney;
		}

		/**
		 * @private
		 */
		public function set landNeedMoney(value:Number):void
		{
			_landNeedMoney = value;
		}

		/**
		 * 升级后土地增加数量 以地图单元格为单位 
		 */
		public function get addLandNum():Number
		{
			return _addLandNum;
		}

		/**
		 * @private
		 */
		public function set addLandNum(value:Number):void
		{
			_addLandNum = value;
		}

		/**
		 * 扩张土地需要的权限 
		 */
		public function get landPow():String
		{
			return _landPow;
		}

		/**
		 * @private
		 */
		public function set landPow(value:String):void
		{
			_landPow = value;
		}

		/**
		 * 当前土地的宽  单元格为单位
		 */
		public function get oldWallW():Number
		{
			return _oldWallW;
		}

		/**
		 * @private
		 */
		public function set oldWallW(value:Number):void
		{
			_oldWallW = value;
		}

		/**
		 * 当前土地的长  单元格为单位 
		 */
		public function get oldWallH():Number
		{
			return _oldWallH;
		}

		/**
		 * @private
		 */
		public function set oldWallH(value:Number):void
		{
			_oldWallH = value;
		}

		/**
		 * 避难所基地等级 
		 */
		public function get houseBuildingLv():Number
		{
			return _houseBuildingLv;
		}

		/**
		 * @private
		 */
		public function set houseBuildingLv(value:Number):void
		{
			_houseBuildingLv = value;
		}
		
		/**
		 * 主建筑的等级是否达到 
		 */		
		public function isReachMainHouseLv():Boolean
		{
			return GV_Map.instance.mapData.havenLv>=houseBuildingLv;
		}

		/**
		 *  拓展之后的围墙宽度 
		 */
		public function get newWallW():Number
		{
			return _newWallW;
		}

		/**
		 * @private
		 */
		public function set newWallW(value:Number):void
		{
			_newWallW = value;
		}

		/**
		 * 拓展之后的围墙高度 
		 */
		public function get newWallH():Number
		{
			return _newWallH;
		}

		/**
		 * @private
		 */
		public function set newWallH(value:Number):void
		{
			_newWallH = value;
		}
		

		/**
		 *当前基地等级 
		 * @return 
		 * 
		 */
		public function get havenLv():int
		{
			return  GV_Map.instance.mapData.havenLv;
		}

		/**
		 *角色等级 
		 * @return 
		 * 
		 */
		public function get playerLv():int
		{
			return GD_Player.instance.playerLv;
		}
		
		/**
		 *当前给力好友数量 
		 * @return 
		 * 
		 */
		public function get friendNumByLv():int
		{
			return  GD_AllFriends.instance.getFriendNumByLv();
		}
		
		/**
		 *金币 
		 * @return 
		 * 
		 */
		public function get money():Number
		{
			return GD_Player.instance.money;
		}
		
		/**
		 *o币 
		 * @return 
		 * 
		 */
		public function get gold():Number
		{
			var g:Number=0;
			if(M_ConfigData.instance.isOpenQQVip)
			{
				var item:GD_Item=GD_Player.instance.getItemByType(10100049);
				if(null==item)
				{
					g=0;
				}else{
					g=item.itemNumber;
				}
			}else{
				g=GD_Player.instance.gold;
			}
				
			return g;
		}
		
		private var _landId:Number;

		private var _landGreade:Number;

		private var _landFriendNum:Number;

		private var _landNeedOMoney:Number;
		
		private var _landNeedMoney:Number;
		
		private var _addLandNum:Number;
		
		private var _landPow:String;
		
		private var _oldWallW:Number;
		
		private var _oldWallH:Number;
		
		private var _houseBuildingLv:Number;
		
		private var _newWallW:Number;
		
		private var _newWallH:Number;

	}
}